using System;
using System.Windows;
using System.Windows.Media;
namespace Coding4Fun.Phone.Controls.Binding
{
	public class FrameworkElementBinding
	{
		public static readonly DependencyProperty ClipToBoundsProperty = DependencyProperty.RegisterAttached("ClipToBounds", typeof(bool), typeof(FrameworkElementBinding), new PropertyMetadata(false, new PropertyChangedCallback(FrameworkElementBinding.smethod_0)));
		public static bool GetClipToBounds(DependencyObject dependencyObject_0)
		{
			return (bool)dependencyObject_0.GetValue(FrameworkElementBinding.ClipToBoundsProperty);
		}
		public static void SetClipToBounds(DependencyObject dependencyObject_0, bool value)
		{
			dependencyObject_0.SetValue(FrameworkElementBinding.ClipToBoundsProperty, value);
		}
		private static void smethod_0(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_NewValue() == dependencyPropertyChangedEventArgs_0.get_OldValue())
			{
				return;
			}
			FrameworkElementBinding.smethod_1(dependencyObject_0, (bool)dependencyPropertyChangedEventArgs_0.get_NewValue());
		}
		private static void smethod_1(object object_0, bool bool_0)
		{
			FrameworkElement frameworkElement = object_0 as FrameworkElement;
			if (frameworkElement == null)
			{
				return;
			}
			FrameworkElementBinding.smethod_3(frameworkElement, bool_0);
			if (bool_0)
			{
				frameworkElement.add_Loaded(new RoutedEventHandler(FrameworkElementBinding.smethod_2));
				frameworkElement.add_SizeChanged(new SizeChangedEventHandler(FrameworkElementBinding.smethod_2));
				return;
			}
			frameworkElement.remove_Loaded(new RoutedEventHandler(FrameworkElementBinding.smethod_2));
			frameworkElement.remove_SizeChanged(new SizeChangedEventHandler(FrameworkElementBinding.smethod_2));
		}
		private static void smethod_2(object sender, RoutedEventArgs e)
		{
			FrameworkElement frameworkElement = sender as FrameworkElement;
			if (frameworkElement == null)
			{
				return;
			}
			FrameworkElementBinding.smethod_3(frameworkElement, FrameworkElementBinding.GetClipToBounds(frameworkElement));
		}
		private static void smethod_3(FrameworkElement frameworkElement_0, bool bool_0)
		{
			if (bool_0)
			{
				RectangleGeometry rectangleGeometry = new RectangleGeometry();
				rectangleGeometry.set_Rect(new Rect(0.0, 0.0, frameworkElement_0.get_ActualWidth(), frameworkElement_0.get_ActualHeight()));
				frameworkElement_0.set_Clip(rectangleGeometry);
				return;
			}
			frameworkElement_0.set_Clip(null);
		}
	}
}
